﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manage/Base.Master" AutoEventWireup="true" CodeBehind="DBRestore.aspx.cs" Inherits="Exhibition.Manage.DBRestore" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellspacing="0" cellpadding="0" width="100%" class="admintable">
        <tr>
            <td>
                <table cellspacing="0" cellpadding="0" class="admintable01">
                    <tr>
                        <td style="width: 20px;">
                            <img src="../images/carfromtable_01.gif" style="margin-top: 2px;" />
                        </td>
                        <td>
                            <b>位置：</b>数据库还原
                        </td>

                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="2" height="30"></td>
        </tr>

        <tr>
            <td colspan="2">
                <div id="search" runat="server">
                    <div style="padding: 10px 20px; border: 1px #eeeeee solid; background: #f7f7f7">
                        &nbsp;
                    <input type="checkbox" id="CheckAllBox" onclick="YXQ.Common.SelAll();" class="checkbox" />
                        全选
                    <asp:Button CssClass="bt_wb1" OnClientClick="return CheckEdit();"  OnClick="btnRestore_Click" runat="server" Text="恢复" />
                        <asp:Button ID="btnDel" CssClass="bt_wb1" OnClick="btnDel_Click" runat="server" Text="删除" />

                    </div>
                </div>

            </td>

        </tr>
        <tr>
            <td colspan="2">
                <div class="listborder" runat="server" id="ShowBakFileList">
                    <dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False"
                        DataSourceForceStandardPaging="false" ClientInstanceName="grid" KeyFieldName="ID">
                        <Columns>
                            <dx:GridViewCommandColumn Caption="选择" ShowSelectCheckbox="true"></dx:GridViewCommandColumn>
                              <dx:GridViewDataTextColumn  FieldName="ID"  Visible="false"></dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="Name" Caption="文件名称"></dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="Notice" Caption="分卷"></dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="Size" Caption="大小(KB)"></dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn FieldName="Date" Caption="创建日期"></dx:GridViewDataTextColumn>
                        </Columns>
                        <Settings ShowHorizontalScrollBar="true" VerticalScrollableHeight="320" ShowVerticalScrollBar="true" ShowGroupedColumns="true" />
                        <SettingsBehavior AllowMultiSelection="true" AllowFocusedRow="True" AutoExpandAllGroups="true" />
                        <SettingsPager Visible="false">
                        </SettingsPager>

                    </dx:ASPxGridView>
                </div>

            </td>
        </tr>
    </table>
    <div class="listborder" runat="server" visible="false" id="ShowRestore">
        <table id="OperateTable" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td align="center" colspan="2" style="padding: 30px 0 20px">
                    <div id="RefreshSchedule">
                        <div class="processline" align="left" style="width: 400px;">
                            <div id="RefreshLen" class="xingmu" style="width: 0px;">
                                <span class="xingmu">0%</span>
                            </div>
                        </div>
                        <span id="CheckBakFile" align="left" style="color: #009900">正在检测当前备份卷是否完整</span>
                        <span id="schedule" align="left" style="display: none">共有{$totalcount}卷需要恢复.</span>
                        <span id="wait1" style="display: none">.</span>
                        <span id="totalcount" align="center" style="display: none"></span>
                        <br />
                        <br />
                    </div>
                </td>
            </tr>
            <tr>
                <td height="30" align="center" colspan="2">
                    <input type="hidden" id="filename" value='' runat="server" />
                    <input type="button" id="btnBeginRestore" value="开始恢复" onclick="RestoreData()" runat="server" class="button" />
                    <input type="button" id="btnReturn" value="返回列表" onclick="window.location.href = 'DBRestore.aspx'" class="button" />
                </td>
            </tr>
        </table>
    </div>
    <asp:HiddenField ID="CheckedIDS" runat="server" Value="0" />


    <script language="javascript" type="text/javascript">

        var count = 0;
        var indexcount = 0
        function CheckEdit() {
            count = 0;
            var ids = GetCheckedBox();
            alert(ids);
            if (ids == "0") {
                alert("对不起请选择要恢复的数据");
                return false;
            }   else {
                document.getElementById("CheckedIDS").value = ids.replace('0,', '');
                return true;
            }
        }

        //获取全部选中CHECKBOX的值集合
        function GetCheckedBox() {
            var ids = "0";
            var InputList = document.getElementsByTagName("input");
            var InputAll = document.getElementById("CheckAllBox");
            for (var j = 0 ; j < InputList.length ; j++) {
                if (InputList[j].type == "checkbox") {
                    if (InputList[j].checked == true) {
                        ids += "," + InputList[j].value;
                        count++;
                        index = indexcount;
                    }
                    indexcount++;
                }
            }
            return ids;
        }

        var isfirst = true;
        /*以下检测当前是否发布*/
        function CheckBakFile() {
            $('wait1').style.display = "";
            HiddenControl();
            var url = 'DBRestore.aspx?ChcekBakFile=true&d=' + Date() + '&filename=' + $('filename').value;
            var Action = '';
            setTimeout('WaitPreData()', 1000);
            var wAjax = new Ajax.Request(url, { method: 'get', parameters: Action, onComplete: ShowCheckTimeOut });
        }

        function ShowCheckTimeOut(OriginalRequest) {
            var originalrequest = OriginalRequest.responseText;
            setTimeout("ShowCheck(" + originalrequest + ")", 1000);
        }

        function ShowCheck(originalrequest) {
            $("wait1").innerHTML = "1";
            $("wait1").style.display = "none";
            $("totalcount").value = originalrequest;
            if (originalrequest != "0") {
                $("CheckBakFile").innerHTML = "备份卷检测完成，共有" + originalrequest + "卷备份卷。可以进行数据恢复。"
                ShowControl();
            }
            else {
                $("CheckBakFile").innerHTML = "检测完毕，备份卷不完整，您无法恢复数据。"
                $('btnReturn').disabled = false;
            }
        }
        /*检测发布结束*/

        /*控件状态改变*/
        function ShowControl() {
            $('btnBeginRestore').disabled = false;
            $('btnReturn').disabled = false;
        }

        function HiddenControl() {
            $('btnBeginRestore').disabled = true;
            $('btnReturn').disabled = true;
        }
        /*控件状态改变*/

<%=startcheck %>

        /*以下是进度条脚本.*/
        function ShowWaitStatus(index) {
            var id = "wait" + index;
            $(id).innerHTML = $(id).innerHTML + ".";
            if ($(id).innerHTML == "............") {
                $(id).innerHTML = ".";
            }
        }
        function WaitPreData() {
            if ($("wait1").innerHTML == "1") {
                return;
            }
            ShowWaitStatus(1);
            setTimeout('WaitPreData()', 1000);
        }

        /*显示统计结果，开始发布页面*/
        function RestoreData() {
            HiddenControl();
            $('CheckBakFile').style.display = "none";
            $('schedule').style.display = "";
            $('wait1').style.display = "";
            $("wait1").innerHTML = ".";
            setTimeout('WaitPreData()', 1000);
            StartCount($('filename').value);
        }

        /*开始统计进度*/
        function StartCount(filename) {
            if (isfirst) {
                $('schedule').innerHTML = " 共有" + $('totalcount').value + "备份卷需要恢复.正在恢复卷头";
            }

            var url = 'DBRestore.aspx?RestoreData=true&d=' + Date() + '&filename=' + filename;
            var Action = '';
            var wAjax = YXQCore.Form.PostData(url, { parameters: Action }, function () { IsOver(); });

        }

        /*进度计算并显示*/
        function IsOver(OriginalRequest) {
            isfirst = false;
            var strRefreshLen = OriginalRequest.responseText.split("$")[2];
            var strFileName = OriginalRequest.responseText.split("$")[1];
            var strErr = OriginalRequest.responseText.split("$")[0];
            if (strRefreshLen == $('totalcount').value) {
                $('wait1').style.display = "none";
                $("wait1").innerHTML = "1";
                $("RefreshLen").style.width = "100%";
                $("RefreshLen").innerHTML = "&nbsp;<span class=\"xingmu\">100%</span>";
                $('schedule').innerHTML = " 共有" + $('totalcount').value + "备份卷需要恢复.已经恢复" + strRefreshLen + "个备份卷.恢复完成";
                $('btnReturn').disabled = false;
                return;
            }
            else if (strErr != "") {
                $('wait1').style.display = "none";
                $("wait1").innerHTML = "1";
                $('schedule').innerHTML = " 数据恢复失败，请与管理员联系。错误描述如下：" + strErr;
                $('btnReturn').disabled = false;
                return;
            }
            else {
                var percent = (strRefreshLen / $('totalcount').value) * 100;
                percent = Math.round(percent);
                $("RefreshLen").style.width = percent + "%";
                $("RefreshLen").innerHTML = "&nbsp;<span class=\"xingmu\">" + percent + "%</span>";
                $('schedule').innerHTML = " 共有" + $('totalcount').value + "备份卷需要恢复.正在恢复" + strRefreshLen + "个备份卷";
                StartCount(strFileName);
            }
        }

    </script>
</asp:Content>
